package day30_278;

/**
 * @ClassName Soluction
 * @Description 二分查找
 * @Author clockTown
 * @Date 2021/6/8 20:47
 * @Version 1.0
 */
/* The isBadVersion API is defined in the parent class VersionControl.
      boolean isBadVersion(int version); */

public class Solution extends VersionControl {
    public int firstBadVersion(int n) {
        int l = 1;
        int r = n;
        int res = n;
        while (l <= r){
            int mid = l + (r - l) / 2;
            if (isBadVersion(mid)){
                res =mid;
                r = mid - 1;
            }else {
                l = mid + 1;
            }
        }
        return res;
    }
}
